<?php
namespace Modules\Frontend\Controllers;

class CaptchaController extends \Phalcon\Mvc\Controller {
	public function indexAction() {
		$Builder = (new \Gregwar\Captcha\CaptchaBuilder(null, new \Gregwar\Captcha\PhraseBuilder(4, '23456789'))) -> build();
		$output = $Builder -> get();
		//$this -> session -> remove('frontendCaptcha');
		//$this -> session -> set('frontendCaptcha', $Builder -> getPhrase());
		$this -> response -> setContentLength(strlen($output)) -> setContentType('image/png') -> setContent($output) -> send();
		exit;
	}

	public function sendCaptchaAction() {
		$code = rand(1111, 9999);
		$this -> SMS::getServiceInstance() -> sendSMS(['t'=>4,'code' => $code, 'mobile' => $this -> request -> getQuery('cellphone')]);
		$this -> response -> setStatusCode(200, 'OK') -> sendHeaders() -> setContentType('application/json', 'UTF-8');
		return $this -> response -> setJsonContent(['code'=>0,'msg'=>'发送成功', 'captcha_token'=>base64_encode(md5($code))]);
	}
}